﻿using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FittyWars.MathUtil
{
    public class Vector
    {
        public float X { get; private set;}
        public float Y { get; private set; }

        public Vector(float x, float y)
        {
            X = x;
            Y = y;
        }

        public Vector(double x, double y)
        {
            X = (float)x;
            Y = (float)y;
        }

        public Vector Add(Vector other)
        {
            return new Vector(X + other.X, Y + other.Y);
        }

        public Vector Subtract(Vector other)
        {
            return new Vector(X - other.X, Y - other.Y);
        }

        public Vector Scale(float f)
        {
            return new Vector(X * f, Y * f);
        }

        public float Cross(Vector other)
        {
            return X * other.Y - Y * other.X;
        }

        public float Size()
        {
            return (float)Math.Sqrt(X * X + Y * Y);
        }

        public float Distance(Vector other)
        {
            return this.Subtract(other).Size();
        }

        public Vector Norm()
        {
            return this.Scale(this.Size());
        }

        public Vector ApplyMatrix(Matrix mat)
        {
            float[] val = mat.Elements;
            return new Vector(
                X * val[0] + Y * val[2] + val[4],
                X * val[1] + Y * val[3] + val[5]
            );
        }
    }
}
